package com.tes.jar;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonParseException;
import jakarta.servlet.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class Jarc implements Servlet {


    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {


        //新建学生类
        Student student = new Student();

        ArrayList<String> books = new ArrayList<String>();
        books.add("数学");
        books.add("语文");
        books.add("英语");
        books.add("物理");
        books.add("化学");
        books.add("生物");
        student.books = books;

        HashMap<String, String> booksMap = new HashMap<String, String>();
        booksMap.put("1", "数学");
        booksMap.put("2", "语文");
        booksMap.put("3", "英语");
        booksMap.put("4", "物理");
        booksMap.put("5", "化学");
        booksMap.put("6", "生物");
        student.booksMap = booksMap;


//        student.tt = "test";

        String stu =  JSON.toJSONString(student);
        System.out.println(stu);


//        try {
//            // 调用GSON jar工具包封装好的toJson方法，可直接生成JSON字符串
//
////            String stu = gson.toJson(student);
////            System.out.println(stu);
//        } catch (Exception e) {
//            System.out.println("错误信息：" + e.getMessage());
//        }



        //        String json = gson.toJson(nt);

        // 输出到界面
//        System.out.println("ggggggggggggggggggxxxxxxxxxx");
//        servletResponse.setContentType("text/plain");
//        servletResponse.setCharacterEncoding("gb2312");
//        servletResponse.setContentType("text/html;charset=utf-8");
//        PrintWriter out = new PrintWriter(servletResponse.getOutputStream());
//        out.print("sssssssssssssssssssxxxxxxxxxxx");
//        out.flush();



    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
